package com.qitmiaojie.controller.utils;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class IdCreateUtil {

    @Autowired
    StringRedisTemplate redisTemplate;

    private final Long BASE_TIME = 1678752000L;
    private final int COUNT_BIT = 32;

    public Long CreateID(String prefix){


        //生成时间戳

//        LocalDateTime nowDate = LocalDateTime.now();
//        long time = nowDate.toEpochSecond(ZoneOffset.UTC) - BASE_TIME;

        //生成序列号

//        String TimeString = nowDate.format(DateTimeFormatter.ofPattern("yyyy:MM:dd"));


//        Long count = redisTemplate.opsForValue().increment("icr:" + prefix + ":" + TimeString);


//        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        //拼接


        return UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE;
//        return time << COUNT_BIT | count;
    }


//    public static void main(String[] args) {
//        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
//        long l = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE;
//        System.out.println(l);
//    }

}
